Back to course home
0% completed
Vote For New Content
LinkedIn Hard
Max Points on a Line (hard)
Solution: Max Points on a Line
Closest Binary Search Tree Value II (hard)
Solution: Closest Binary Search Tree Value II
Word Ladder (hard)
Solution: Word Ladder
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Same Tree (medium)
Problem Statement
Given the roots of two binary trees 'p' and 'q', write a function to check if they are the same or not.
Two binary trees are considered the same if they met following two conditions:
- Both tree are structurally identical.
- Each corresponding node on both the trees have the same value.
Example 1:
Given the following two binary trees:
Output: true
Explanation: Both trees are structurally identical and have same values.
Example 2:
Given the following two binary trees:
Output: false
Explanation: Trees are structurally different.
Example 3:
Given the following two binary trees:
Output: false
Explanation: Corresponding nodes have different value ( 4 & 9 ).
Constraints:
- The number of nodes in both trees is in the range
[0, 100]. - -104 <= Node.val <= 104
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Maximum Product Subarray
Solution: Same Tree
Mark as Completed
On this page
Problem Statement
Try it yourself